package com.xiaojie.extension;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author wangye
 * @classname BeanPostProcessorImpl
 * @date 2021/4/14 13:42
 **/
@Component
public class BeanPostProcessorImpl implements BeanPostProcessor {

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof RabbitTemplate){
            //确认消息是否从交换器路由到队列
            RabbitTemplate rabbitTemplate =  (RabbitTemplate)bean;
            rabbitTemplate.setReturnCallback((message, replyCode, replyText, exchange, routingKey) -> {
                System.out.println(String.format("message:%s,replyCode:%s,replyText:%s,exchange:%s,routingKey:%s", message, replyCode, replyText, exchange, routingKey));
            });
        }
        return bean;
    }
}
